package com.clever.mall.controller;

import com.clever.mall.commons.dto.DiscountRequestParam;
import com.clever.mall.commons.result.BaseResult;
import com.clever.mall.service.DiscountService;
import com.clever.mall.vo.DiscountVo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/discount")
public class DiscountController {
    @Resource
    DiscountService discountService;

    //以关键字查询一类的红包
    @RequestMapping("/findByWord")
    public BaseResult findByWord(String msg) {
        List<DiscountVo> byWord = discountService.findByWord(msg);
        return BaseResult.success(byWord);
    }

    //领取优惠券1.已存在增加数量 2.不存在创建关联
    @RequestMapping("/add")
    public BaseResult add(@RequestBody List<DiscountRequestParam> requestParamList) {
        int add = discountService.add(requestParamList);
        return BaseResult.success(add);
    }
}
